package cn.e4j.modular.crm.controller.base;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.common.exception.BizExceptionEnum;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.modular.crm.entity.MmrmT;
import cn.e4j.modular.crm.service.MmrmTService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 产品故障类别维护 控制层
 * @author mengyb
 * @date 2019-04-10
 */
@Controller
@RequestMapping("/base/gwai670")
public class Gwai670Controller extends BaseController {

    @Autowired
    private MmrmTService mmrmTService;

    /**
     * 跳转至产品故障类别维护主界面
     *
     * @return
     */
    @RequiresPermissions("base:gwai670:init")
    @RequestMapping(value = {"", "/init"})
    public String index() {
        return "/pc/crm/base/gwai670.html";
    }

    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/getList")
    @ResponseBody
    public ResponseData getList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();

        List<Map<String, Object>> list = mmrmTService.getList(inDto, page);

        return new PageReData(page, list);

    }

    /**
     * 产品分类开窗
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/getGwahPageList")
    @ResponseBody
    public ResponseData getGwahPageList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();

        List<Map<String, Object>> list = mmrmTService.getGwahPageList(inDto, page);

        return new PageReData(page, list);

    }
    /**
     * 获取产品分类列表
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/getGwahList")
    @ResponseBody
    public Dto getGwahList(@DtoParam DtoWapper dtoWapper) {

        Dto indto=dtoWapper.getDto();

        List<Map<String, Object>> list = mmrmTService.getGwahList(indto);

        Dto outDto= Dtos.newDto();

        outDto.put("list",list);

        return outDto;

    }

    /**
     * 故障开窗
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/getMmrlPageList")
    @ResponseBody
    public ResponseData getMmrlPageList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();

        List<Map<String, Object>> list = mmrmTService.getMmrlPageList(inDto, page);

        return new PageReData(page, list);

    }

    /**
     * 获取故障列表
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/getMmrlList")
    @ResponseBody
    public Dto getMmrlList(@DtoParam DtoWapper dtoWapper) {

        Dto indto=dtoWapper.getDto();

        List<Map<String, Object>> list = mmrmTService.getMmrlList(indto);

        Dto outDto= Dtos.newDto();

        outDto.put("list",list);

        return outDto;

    }


    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/add")
    @ResponseBody
    public ResponseData add(MmrmT mmrmT) {
        if (mmrmTService.existedTheParams(mmrmT)) {
            return new ErrorResponseData(BizExceptionEnum.EXISTED_THE_PARAMS.getCode(),
                    BizExceptionEnum.EXISTED_THE_PARAMS.getMessage());
        } else {
            mmrmTService.add(mmrmT);
            return SUCCESS_TIP;
        }
    }

    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/edit")
    @ResponseBody
    public ResponseData edit(MmrmT mmrmT) {
        mmrmTService.edit(mmrmT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/delRow")
    @ResponseBody
    public ResponseData delRow(MmrmT mmrmT) {
        mmrmTService.delRow(mmrmT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai670:init")
    @RequestMapping("/delRows")
    @ResponseBody
    public ResponseData delRows(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<MmrmT> mmrmTList = inDto.getReqList(MmrmT.class);
        mmrmTService.delRows(mmrmTList);
        return SUCCESS_TIP;
    }


}
